const joi = require("joi");

const password = joi
  .string()
  .pattern(/^[\S]{6,12}$/)
  .required();

const username = joi.string().alphanum().min(3).max(10).required();
const avatar = joi.string().dataUri().required();

exports.reg_login_schema = {
  // 对body中的表单数据进行验证， 如有需要也可对req.query 或req.params 里的数据进行验证
  body: {
    username,
    password,
    // repassword: joi.ref("password"),
  },
};

// 如果schema里没有保护username, 或email, 则即使用户在请求body里填写了这些信息也无法更新
exports.update_userinfo_schema = {
  body: {
    username,
    id: joi.number().integer().min(1).required(),
    nickname: joi.string().required(),
    email: joi.string().email().required(),
  },
};

exports.update_password_schema = {
  body: {
    oldPwd: password,
    newPwd: joi.not(joi.ref("oldPwd")).concat(password),
  },
};

exports.updata_avatar_schema = {
  body: {
    avatar,
  },
};
